/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.classes;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 *
 * @author Sinh
 */
public class Book {

    // member class là 1 loại của nested class
    public class Author {

    }
    /**
     * An array to store five ISBN numbers
     */
    // phải xử lí bằng method static
    static String publisher = "test"; // class varible
    // phải xử lí bằng method thường,
    int isbn[];
    int books[][];
    byte bookCount;

    // static initializer
    static {
        if (true) {
            publisher = "test";
        } else {
            publisher = "test2";
        }
    }

    /**
     * create a new instance of Book class
     */
    public Book() {
        bookCount = 0;
        isbn = new int[5];
        books = new int[3][3];
    }

    // class method
    public String getPublisher() {
        return Book.publisher;
    }

    void setIsbn() {
        Scanner r = new Scanner(System.in);



        // Iterate until five ISBN number re accepted
        for (int index = 0; index < isbn.length; index++) {
            isbn[index] = r.nextInt();
        }
    }

    void getIsbn() {
        // display the ISBN numbers stored in the array
        System.out.printf("display five numbers:\n");
        for (int index = 0; index < isbn.length; index++) {
            System.out.println(isbn[index]);
        }
    }

    void cach() {
        int sum = 0;
        int[] numArray = {6, 7, 8, 4};
        System.out.printf("array values are:");

        //for-each loop
        for (int index : numArray) {
            System.out.println(index);
            sum += index;
        }
        System.out.println("sum = " + sum);
    }

    void addBook() {
        Scanner input = new Scanner(System.in);
        //add a book only if there is space in the array.
        for (int count = 0; count < books.length; count++) {
            if (bookCount < books.length) {
                //Accept the ISBN number
                System.out.println("Enter the ISBN number of the book:");
                books[bookCount][0] = input.nextInt();
                //Accept the number of pages in the book
                System.out.println("enter the number of pages in the books:");
                books[bookCount][1] = input.nextInt();
                System.out.println("enter the year of pages in the books:");
                books[bookCount][2] = input.nextInt();
                bookCount++;
            } else {
                System.out.println("sorry!can not continue");
            }
        }
    }

    void displayBooks() {
        if (bookCount > 0) {
            System.out.println("\nISBN \tPages \tPublication Year");
            System.out.println("--------------------------------");

            //Iterate until all the book details are displayed
            for (int rowIndex = 0; rowIndex < bookCount; rowIndex++) {
                System.out.printf("%d\t", books[rowIndex][0]);
                System.out.printf("%d\t\t", books[rowIndex][1]);
                System.out.printf("%d\n", books[rowIndex][2]);
            }
        }
    }
}
